<div class="btn-group">
    @if($delivery->status == 4 && \Encore\Admin\Facades\Admin::user()->can('os-in.os.box'))
        <button style="margin-left: 5px;" class="btn btn-sm btn-warning form-action" data-id="{{ $id }}" data-action="addedBoxDetail"><i class="fa fa-briefcase"></i>&nbsp;录入完成</button>
    @endif
    @if($delivery->status > 4)
        <a style="margin-left: 5px;" href="/xqc/overseas-in/os-dropshipping-box/{{ $id }}/download" target="_blank" class="btn btn-sm btn-default"><i class="fa fa-download"></i>&nbsp;导出装箱信息</a>
    @endif
</div>
<script language="JavaScript" type="text/javascript">
    $(function () {
        $('.form-action').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            var action = $(this).data('action');
            swal({
                title: "确定录入完成？",
                text : "确定装箱信息录入完成？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        $.ajax({
                            method: 'post',
                            url: '/xqc/overseas-in/os-dropshipping-ajax',
                            data: {
                                _token:"{{ csrf_token() }}",
                                action:action,
                                param:id
                            },
                            success: function (data) {
                                resolve(data);
                            }
                        });
                    });
                }
            }).then(function(result) {
                var data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        toastr.success('提交成功 !');
                        location.href = '/xqc/overseas-in/os-dropshipping/{{ $id }}/edit';
                    } else {
                         swal(data.message, '', 'error');
                    }
                }
            });
        });
    });
</script>
